package com.cbtx.tablet.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.text.TextUtils
import android.view.LayoutInflater
import android.view.View
import android.view.Window
import android.widget.TextView
import com.cbtx.tablet.R

/**
 * author : joker.peng
 * e-mail : joker@fiture.com
 * date   : 2021/7/5 3:33 AM
 * desc   :
 */
class TipsDialog : Dialog {

    var mContent: String? = null
    var mAgree: String? = null
    var onDialogListener: OnDialogListener? = null

    constructor(context: Context) : super(context, R.style.MMTheme)

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        requestWindowFeature(Window.FEATURE_NO_TITLE)
        initView()
    }

    private fun initView() {
        val contentView: View = LayoutInflater.from(context).inflate(R.layout.base_dialog_comfig, null)
        val tvContent = contentView.findViewById<TextView>(R.id.tv_content)
        val tvAgree = contentView.findViewById<TextView>(R.id.tv_agree)
        if (!TextUtils.isEmpty(mContent)) {
            tvContent.text = mContent
        }
        if (!TextUtils.isEmpty(mAgree)) {
            tvAgree.text = mAgree
            tvAgree.visibility = View.VISIBLE
            tvAgree.setOnClickListener {
                if (onDialogListener != null) {
                    onDialogListener?.onAgree()
                    dismiss()
                }
            }
        }
        setContentView(contentView)
    }

    fun setContent(mContent: String):TipsDialog {
        this.mContent = mContent
        return this
    }


    fun setAgree(mAgree: String): TipsDialog {
        this.mAgree = mAgree
        return this
    }

    fun setOnDialogListener(onDialogListener: OnDialogListener): TipsDialog {
        this.onDialogListener = onDialogListener
        return this
    }

    interface OnDialogListener {
        fun onCancel()
        fun onAgree()
    }
}